package com.bauer.java.datagen.mysql.dao;

import com.bauer.java.datagen.mysql.mapper.SalesMapper;
import com.bauer.java.datagen.mysql.po.Sales;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author ：rui.wei
 * @Date ：Created in 11:37 2019/7/29
 * @Description：
 */
public class MysqlGen {

    private static ExecutorService executorService = new ThreadPoolExecutor(5, 10, 100L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>());

    public static void main(String[] args) {
        String[] coutry = new String[]{"江西"};
        String[] citys = new String[]{"南昌","九江","上饶","抚州","宜春","吉安","赣州","景德镇","萍乡","新余","鹰潭"};

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("mysql/spring-mybatis.xml");

        SalesMapper salesMapper = applicationContext.getBean(SalesMapper.class);
        for (String province : coutry) {

            for (String city : citys) {

                executorService.submit(() -> {
                    try {
                        for (int i = 2000; i <= 2019; i++) {
                            for (int j = 1; j <= 12; j++) {

                                List<Sales> list = new ArrayList<>(30);
                                for (int k = 1; k <= 30; k++) {

                                    Sales sales = new Sales();
                                    sales.setCountry(province);
                                    sales.setCity(city);
                                    sales.setYear(i);
                                    sales.setMoth(j);
                                    sales.setDay(k);
                                    sales.setAmount(new Random().nextInt(100000));
                                    list.add(sales);
                                }
//                                salesMapper.batchInsert(list);
                            }
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });

            }
        }
    }
}
